﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

public partial class mystudy_Study_TopMenu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["sUserName"] == null)
        {

            Response.Write("<script language=javascript>alert('未登录或登录已到期，请返回登录页面重新登录！');window.close();</script>");
            Response.Write("<script language=javascript> window.open('../logout.aspx',target='_top')</script>");
            return;
        }
        if (!IsPostBack)
        {
            lblRole.Text = Session["sRole"].ToString();
            lblusername1.Text = Session["sUsername1"].ToString();
            //        有效用户的判断：（返回目录）
            //Session[sRole]=学员	Session[sKecheng].indexof(session[sid])>0| Session[sKechenged].indexof(session[sid])>0
            //Session[sRole]=老师	Session[sKecheng].indexof(session[sid])>0
            //Session[sRole]=机构	Jigou=session[sUsername1]
            bool z1 = (Session["sRole"].ToString() == "学员" | Session["sRole"].ToString() == "老师") & (Session["sKecheng"].ToString().IndexOf(Session["sid"].ToString()) > 0 | Session["sKechenged"].ToString().IndexOf(Session["sid"].ToString()) > 0); //课程在学员或老师的已学或正学/已教正教课程里
            if (Session["sRole"].ToString() == "老师" & Session["slaoshi"].ToString() == Session["sUsername"].ToString())
            {
                z1 = true;
            }
            bool z2 = Session["sRole"].ToString() == "管理员"; //对平台管理员，所有内容均可操作
            bool z3 = Session["sRole"].ToString() == "机构" & Session["sJigou"].ToString() == Session["skechengjigou"].ToString();  //对机构用户，只要课程所属机构是该机构即可操作
            //除了上述4中情况之外，其他人员均视为无效用户
            if (z1 | z2 | z3)
            {
                HylBBS.Enabled = true;
                HylDoult.Enabled = true;

            }
            else
            {
                HylBBS.Enabled = false;
                HylDoult.Enabled = false;

            }
            //判断字符串的长度,一个汉字按2个长度计算
            lblJigou.Text = Session["sJigou"].ToString();

            string pattern = "[^\x00-\xff]";
            string _pattern = "[\x00-\xff]";
            MatchCollection chinese = Regex.Matches(lblJigou.Text, pattern, RegexOptions.Multiline);
            MatchCollection notChinese = Regex.Matches(lblJigou.Text, _pattern, RegexOptions.Multiline);
            string temp = String.Empty;
            foreach (Match match in chinese)
            {
                temp += match.Value;
                temp = temp.Replace(match.Value, "rr");
            }
            foreach (Match match in notChinese)
            {
                temp += match.Value;
            }

            if (temp.Length > 9)
            {
                lblJigou.Font.Size = new FontUnit(25, UnitType.Pixel);
            }
            if (temp.Length > 11)
            {
                lblJigou.Font.Size = new FontUnit(22, UnitType.Pixel);
            }
            if (temp.Length > 20)
            {
                lblJigou.Font.Size = new FontUnit(15, UnitType.Pixel);
            }

        }
    }
}
